﻿using LeShiTao_Library.WeChat.Public_WC;
using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using Top.Api.Response;

namespace TB_WS.Class
{
   public class JST_Trade
    {
    
        public static DataSet Get_Trade(string Seller_Nick)
        {
            string sql = "select tid,buyer_nick,created FROM jdp_tb_trade WHERE seller_nick ='" + Seller_Nick
                + "' and status ='TRADE_FINISHED' and jdp_response like '%buyer_rate\":true%' and jdp_response LIKE '%seller_rate\":false%' and created between DATEADD(day,-30,getdate()) and getdate()";
            return Class.Unit.Trade_DB_Conn.select(sql);
        }
        public static DataSet Get_Trade(string Seller_Nick,string Goods_ID)
        {
            string sql = "select tid,buyer_nick,created FROM jdp_tb_trade WHERE seller_nick ='" + Seller_Nick
                + "' and status ='TRADE_FINISHED' and jdp_response like '%buyer_rate\":true%' and jdp_response LIKE '%seller_rate\":false%' and jdp_response LIKE '%"+Goods_ID+"%' and created between DATEADD(day,-30,getdate()) and getdate()";
            return Class.Unit.Trade_DB_Conn.select(sql);
        }

        public static DataSet Search_Trade(string Buyer_Nick)
        {
            string sql = "select * from jdp_tb_trade where buyer_nick='" + Buyer_Nick + "'";
            return Class.Unit.Trade_DB_Conn.select(sql);
        }

        public static DataSet Search_Trade_Not_Seller(string Buyer_Nick,string Seller_Nick)
        {
            string sql = "select * from jdp_tb_trade where buyer_nick='" + Buyer_Nick + "' and seller_nick !='"+Seller_Nick+"'";
            return Class.Unit.Trade_DB_Conn.select(sql);
        }

        public static string use_WL_get_Tid(string Seller_Nick,string WL_ID,string status)
        {
            string sql = "select Tid from jdp_tb_trade where seller_nick='" + Seller_Nick + "' and status='"+status+"' and jdp_response like '%" + WL_ID + "%'";
            return Unit.Trade_DB_Conn.select(sql).Tables[0].Rows[0][0].ToString();
        }

        public static string get_last_RDS_mod()
        {
            string sql = "select last_time from RDS_Trade_Up_List order by id desc";
            return Unit.db_Conn.scalar(sql);
        }


        public static void insert_Now_Time(string Date_Type)
        {
            string Now_DateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
            string sql = "insert into RDS_DateTime_List values('"+Date_Type+"','" + Now_DateTime + "')";
            Unit.db_Conn.Nonquery(sql);
        }
        public static DataSet Get_Last_RD_Data()
        {
            
            string sql = "select * from jdp_tb_trade where jdp_modified>'" + Get_Last_Date_Time("Modified") + "' and status !='TRADE_FINISHED' and status !='TRADE_CLOSED' and status !='TRADE_CLOSED_BY_TAOBAO'";
            insert_Now_Time("Modified");//更新最后一次时间
            return Unit.Trade_DB_Conn.select(sql);
        }
        public static string Get_Last_Date_Time(string Date_Type)
        {
            string sql = "select Date_Time from RDS_DateTime_List where Date_Type='" + Date_Type + "' order by id desc";
            return Class.Unit.db_Conn.scalar(sql);
        }
        public static DataSet Get_Tid_List_Create_Desc(string Last_Time)
        {
            string sql = "select * from jdp_tb_trade where created > '" + Last_Time + "' order by created desc";
            insert_Now_Time("Created");//更新最后一次时间
            return Unit.Trade_DB_Conn.select(sql);
        }

        public static DataSet Get_Pay_Tids_Desc(string Seller_Nick)
        {
            string sql = "select tid,buyer_nick,created from dbo.jdp_tb_trade where status='WAIT_SELLER_SEND_GOODS' and seller_nick='"+Seller_Nick+"' order by created desc";
            return Unit.Trade_DB_Conn.select(sql);
        }
    }
}
